package com.lb.jwitter.action;


import java.util.Collection;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTiet;
import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTietService;
import com.lb.jwitter.service.TblDKMHDotDKHocVien;
import com.lb.jwitter.service.TblDKMHDotDKHocVienService;

import com.lb.jwitter.service.TblDKMHDotDKNhom;
import com.lb.jwitter.service.TblDKMHDotDKNhomService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblDKMHDotDKNhomtblDKMHDotDKHocVienChiTietEditFormAction{
    private int id; 
    public void setId(int id) {
       this.id = id;
 }

    public int getId() {
       return id;
 }

    private Date today; 
    public Date getToday() { return new Date(); } 

    private TblDKMHDotDKHocVienChiTiet tblDKMHDotDKHocVienChiTiet; 
    public TblDKMHDotDKHocVienChiTiet getTblDKMHDotDKHocVienChiTiet() { 
        return tblDKMHDotDKHocVienChiTiet; 
    } 
    private TblDKMHDotDKNhom tblDKMHDotDKNhom; 
    public TblDKMHDotDKNhom getTblDKMHDotDKNhom() { 
        return tblDKMHDotDKNhom; 
    } 
    private Collection<TblDKMHDotDKHocVienChiTiet> tblDKMHDotDKHocVienChiTiets; 
    public Collection<TblDKMHDotDKHocVienChiTiet>  getTblDKMHDotDKHocVienChiTiets() {
         return tblDKMHDotDKHocVienChiTiets; 
      } 

    private TblDKMHDotDKHocVienChiTietService tblDKMHDotDKHocVienChiTietService; 

    private Collection<TblDKMHDotDKHocVien> tblDKMHDotDKHocViens; 
    public Collection<TblDKMHDotDKHocVien>  getTblDKMHDotDKHocViens(){ 
              return tblDKMHDotDKHocViens; 
     } 

    private TblDKMHDotDKHocVienService tblDKMHDotDKHocVienService; 

    private Collection<TblDKMHDotDKNhom> tblDKMHDotDKNhoms; 
    public Collection<TblDKMHDotDKNhom>  getTblDKMHDotDKNhoms(){ 
              return tblDKMHDotDKNhoms; 
     } 

    private TblDKMHDotDKNhomService tblDKMHDotDKNhomService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    today = new Date(); 
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_DKMH_DotDK_HocVien_ChiTiet", "sua")){ 
        return "noprivilege"; 
    }        tblDKMHDotDKHocVienChiTietService = (TblDKMHDotDKHocVienChiTietService) context.getBean("tbl_DKMH_DotDK_HocVien_ChiTietClient"); 
        tblDKMHDotDKHocVienService = (TblDKMHDotDKHocVienService) context.getBean("tbl_DKMH_DotDK_HocVienClient"); 

        tblDKMHDotDKNhomService = (TblDKMHDotDKNhomService) context.getBean("tbl_DKMH_DotDK_NhomClient"); 

        tblDKMHDotDKHocVienChiTiet = tblDKMHDotDKHocVienChiTietService.gettblDKMHDotDKHocVienChiTiet(new Long(id)); 
        tblDKMHDotDKHocViens = tblDKMHDotDKHocVienService.findAlltblDKMHDotDKHocVien(0, 0);

        tblDKMHDotDKNhom = tblDKMHDotDKHocVienChiTiet.getNhomDKId(); 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi EditForm tbl_DKMH_DotDK_HocVien_ChiTiet Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
